﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web.Mvc;
using Web7.Apps.Account.Services;
using Web7.Core.Apps;
using Web7.Mvc.ViewModels;
using Web7.Core.Security;

namespace Web7.Apps.Account.Controllers
{
    public class AccountController : Controller ///, IAppSubMenu
    {
        //protected IUserService UserService;
        //protected IRoleService RoleService;
        //public AccountController(IUserService userService, IRoleService roleService)
        //{
        //    UserService = userService;
        //    RoleService = roleService;
        //}
        //public ActionResult Index(int? page)
        //{
        //    int pageIndex = 1;
        //    int.TryParse(Request["page"], out pageIndex);

        //    if (page == null || page <= 0)
        //    {
        //        page = 1;
        //    }
        //    Expression<Func<User, bool>> predicate = f => f.Id > 0;
        //    const int pageSize = 10;
        //    var userPageList = new PagedList<User>(UserService.Fetch(
        //            predicate,
        //            p => p.Desc(f => f.Id),
        //            (page.Value - 1) * pageSize,
        //            pageSize), page.Value, pageSize, UserService.Count(predicate));

        //    return View((PagedList<User>)userPageList);
        //}

        //public ActionResult Logon()
        //{
        //    return View();
        //}

        //#region User Operate
        //public RedirectToRouteResult UserDel(int id)
        //{
        //    UserService.Delete(new int[] { id });
        //    return RedirectToAction("Index");

        //}
        ////public IEnumerable<User> GetUserList(int? page)
        ////{
        ////    if (page == null || page <= 0)
        ////    {
        ////        page = 1;
        ////    }
        ////    Expression<Func<User, bool>> predicate = f => f.Id > 0;
        ////    const int pageSize = 10;
        ////    var userPageList = new PagedList<User>(UserService.Fetch(
        ////            predicate,
        ////            p => p.Desc(f => f.Id),
        ////            (page.Value - 1) * pageSize,
        ////            pageSize), page.Value, pageSize, UserService.Count(predicate));

        ////    return userPageList;
        ////}
        //[HttpGet]
        //public User GetUser(int id)
        //{
        //    return UserService.Get(id);
        //}

        //[HttpGet]
        //public ViewResult UserCrt()
        //{
        //    return View();
        //}

        //[HttpPost]
        //public RedirectToRouteResult UserCrt(FormCollection collection)
        //{
        //    var user = new User
        //                   {

        //                       Username = collection["UserName"],
        //                       Password = collection["Password"],
        //                       Email = collection["Email"],
        //                       Status = (UserStatus)Enum.Parse(typeof(UserStatus), collection["Status"]),
        //                       CreationDate = DateTime.Now,
        //                       UserGroup = new UserGroup { Id = 1 }
        //                   };

        //    UserService.Create(user);

        //    return RedirectToAction("Index");
        //}

        //[HttpGet]
        //public User UserEdt(int id)
        //{
        //    return UserService.Get(id);
        //}

        //[HttpPost]
        //public RedirectToRouteResult UserEdt(FormCollection collection, int id)
        //{
        //    var user = UserService.Get(id);

        //    user.Username = collection["UserName"];
        //    user.Email = collection["Email"];
        //    user.Status = (UserStatus) Enum.Parse(typeof (UserStatus), collection["Status"]);
        //    user.UserGroup = new UserGroup {Id = 1};
            
        //    UserService.Update(user);

        //    return RedirectToAction("Index");
        //}
        //#endregion

        //#region UserGroup Operate

        //#endregion

        //#region Role Operate

        //public List<Role> Role()
        //{
        //    return (List<Role>)RoleService.Fetch(
        //        f => f.RoleName.Length > 0,
        //        p => p.Desc(f => f.Id),
        //        0,
        //        10
        //        ).ToList();
        //}

        //[HttpGet]
        //public ViewResult RoleCrt()
        //{
        //    return View();
        //}

        //[HttpPost]
        //public RedirectToRouteResult RoleCrt(FormCollection collection)
        //{
        //    var role = new Role()
        //                   {
        //                       RoleName = collection["roleName"],
        //                       DisplayOrder = 1,
        //                       IsSystem = false
        //                   };
        //    RoleService.Create(role);

        //    return RedirectToAction("Role");
        //}

        //public ViewResult RoleDel(int id)
        //{
        //    return View();
        //}

        //[HttpGet]
        //public ViewResult RoleEdt(int id)
        //{
        //    return View();
        //}

        //[HttpPost]
        //public ViewResult RoleEdt(FormCollection collection, int id)
        //{
        //    return View();
        //}

        //#endregion

        //public Web7ViewModelItem<AppSubMenuItemList> SubMenu()
        //{
        //    return null;
        //}
    }
}
